var markers = new Array();
var map = null;

function geoCoding(address){
	var marker = null;
	var geocoder = new google.maps.Geocoder();
	var image = 'img/church.png';
	var myLatlng = null;
	geocoder.geocode( { 'address': address}, function(results, status){
	if (status == google.maps.GeocoderStatus.OK){
		myLatlng = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());
		marker = new google.maps.Marker({map:map,draggable:true,animation: google.maps.Animation.DROP,position: myLatlng,icon: image});
		marker.setMap(map);
		markers.push(new google.maps.Marker({map:map,draggable:true,animation: google.maps.Animation.DROP,position: myLatlng,icon: image}));
	}});
	alert(markers[0].getPosition());
}

function initialize() {

	var address=$("#txtAddress").val();
	var geocoder = new google.maps.Geocoder();
	var marker = null;
	geoCoding(address);
	
	var pinkParksStyles = [{featureType: "all",stylers: [{ invert_lightness: true },{ hue: "#00d4ff" },{ saturation: 35 },{ lightness: -25 },{ gamma: 1.43 },{ visibility: "simplified" }]}];
	var pinkMapType = new google.maps.StyledMapType(pinkParksStyles,{name: "night style"});
	var mapOptions = {zoom: 17,center: new google.maps.LatLng(markers[0].getPosition().lat(),markers[0].getPosition().lng()),mapTypeControlOptions: {mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'pink_parks']}};
	var map = new google.maps.Map(document.getElementById('map'),mapOptions);
	//marker = new google.maps.Marker({map:map,draggable:true,animation: google.maps.Animation.DROP,position: myLatlng,icon: image}).setMap(map);
	map.mapTypes.set('pink_parks', pinkMapType);
	map.setMapTypeId('pink_parks');
	
	/*geocoder.geocode( { 'address': address}, function(results, status) {
	if (status == google.maps.GeocoderStatus.OK){
	  // Create a new StyledMapType object, passing it the array of styles,
	  // as well as the name to be displayed on the map type control.
	  var pinkMapType = new google.maps.StyledMapType(pinkParksStyles,
		{name: "Pink Parks"});
		marker = new google.maps.Marker({map: map,draggable: true});
		var image = 'img/church.png';
		var myLatlng = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());
	  // Create a map object, and include the MapTypeId to add
	  // to the map type control.
	  var mapOptions = {
		zoom: 17,
		center: new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng()),
		mapTypeControlOptions: {
		  mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'pink_parks']
		}
	  };
	  var map = new google.maps.Map(document.getElementById('map'),
		mapOptions);
		marker = new google.maps.Marker({
			map:map,
			draggable:true,
			animation: google.maps.Animation.DROP,
			position: myLatlng,
			icon: image
			}).setMap(map);

	  //Associate the styled map with the MapTypeId and set it to display.
	  map.mapTypes.set('pink_parks', pinkMapType);
	  map.setMapTypeId('pink_parks');
	}
	});*/
}

function toggleBounce() {
	if (marker.getAnimation() != null) {marker.setAnimation(null);
	}else{marker.setAnimation(google.maps.Animation.BOUNCE);}
}

$(document).ready(function(){ 
	/*var map = null;
	var geocoder = null;
	var address = null;
	var markers = []; 
	var geocoder = new google.maps.Geocoder();
	var marker = null;*/


	$("#bt_start").live("click",function(){
	
		/*address=$("#txtAddress").val();
		geocoder.geocode( { 'address': address}, function(results, status) {
		if (status == google.maps.GeocoderStatus.OK) {
			//alert("Lat: "+results[0].geometry.location.lat()+", Long: "+results[0].geometry.location.lng());
			marker = new google.maps.Marker({map: map,draggable: true});
			var image = 'img/church.png';
			var myLatlng = new google.maps.LatLng(results[0].geometry.location.lat(),results[0].geometry.location.lng());
			var myOptions = {	zoom: 15,
								center: myLatlng,
								mapTypeId: google.maps.MapTypeId.ROADMAP}
			var map = new google.maps.Map(document.getElementById("map"), myOptions);
			marker = new google.maps.Marker({
			map:map,
			draggable:true,
			animation: google.maps.Animation.DROP,
			position: myLatlng,
			icon: image
			});
		}else{alert("Le geocodage n\'a pu etre effectue pour la raison suivante: " + status);}
		});*/
		
		//google.maps.event.addListener(marker, 'click', toggleBounce);
		initialize();
		$("#game").fadeIn();
	});
	
	
});

/*

 // Create a draggable marker which will later on be binded to a
        // Circle overlay.
        var marker = new google.maps.Marker({
          map: map,
          position: new google.maps.LatLng(35, 0),
          draggable: true,
          title: 'Drag me!'
        });
        // Add a Circle overlay to the map.
        var circle = new google.maps.Circle({
			map: map,
			radius: 3000000; // 3000 km
			fillColor: "#3da5e1",   
			fillOpacity: 0.5,   
			strokeColor: "#2b546b",   
			strokeWeight: 1});
        // Since Circle and Marker both extend MVCObject, you can bind them
        // together using MVCObject's bindTo() method.  Here, we're binding
        // the Circle's center to the Marker's position.
        // http://code.google.com/apis/maps/documentation/v3/reference.html#MVCObject
        circle.bindTo('center', marker, 'position');
*/

